//
//  UILabel+XExtension.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/2.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "UILabel+XExtension.h"

@implementation UILabel (XExtension)

- (CGRect)setXFont:(UIFont *)font{
    self.font = font;
    
    if (self.text == nil) {
        NSAssert(false, @"UILabel(XExtension)警告，在设置XFont前需先设置当前label的文本");
    }
    
    CGRect textRect = [self calculateBounds];
    return textRect;
}

- (CGRect)calculateBounds{
    UIFont *font = self.font;
    NSString *text = self.text;
    CGRect textRect;
    
    if (text != nil) {
        textRect = [self.text boundingRectWithSize:[UIScreen mainScreen].bounds.size options:NSStringDrawingUsesLineFragmentOrigin
                                        attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil]
                                           context:nil];
    }
    
    return textRect;
}

@end
